<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="nav" id="navlist"></div>
    <script>
        var navlist=['首页','免费资源','课程中心','IT学院','学员故事','线上学院','技术社区'];
        var str='<ul>';
        for (var i in navlist){
            str+='<li><a>'+navlist[i]+'</a></li>';
        }
        str+='</ul>'
        document.getElementById('navlist').innerHTML=str;
    </script>
    <script>
        var arr=['phoato','tomato','chillies','green-pepper'];
        var search='cucumber';
        if(arr.indexOf(search)===-1){
            arr.push(search);
            console.log('更新后的数组为：'+arr);
        }
        else if(arr.indexOf(search)>-1){
            console.log(search+'元素已经在arr数组中了。')
        }
    </script>
    <script>
        var arr=['sky','wind','snow','sun'];
        arr.splice(4,0,'hall','sun');
        console.log(arr);
        var r=[];
    </script>
    <script>
        var arr=[1,2,3,4,2,5,6,2,7,2];
        var index = 0, newarr = [];
        for( var i in arr){
            if(arr[i]!==2){
                newarr[index]=arr[i];
                ++index;
            }
            console.log(newarr);
        }
    </script>
    <script>
        var arr=['a','b','d','d','c','d','d'];
        var search='d';
        var newarr=[],i=j=0;
        while(i<arr.length){
            var res=arr.indexOf(search,i);
            if(res!==-1){
                newarr[j]=res;
                i=res+1;
                ++j;
            }
        }
        console.log('arr中元素d出现的次数：'+newarr.length+';对应的所有索引下标:'+newarr);
    </script>
    <script>
        var arr=[]
        for(var i=0;i<10;i++){
            var num =Math.floor(Math.random()*91+10);//[0,90]+10
            console.log('num='+num);
            arr.unshift(num);
        }
        console.log(arr);
    </script>
</body>

</html>